﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows;
using Red.Controls.Diagrams.Declarators;
using Red.Controls.Diagrams.ViewModels;

namespace Red.Controls.Diagrams.Dummy
{
    internal class DummyObjectManager : BaseObjectManager, IObjectManager
    {
        #region Data

        private readonly NodeDeclarator _declarator;

        #endregion Data

        #region C-tor

        public DummyObjectManager( DiagramViewModel viewModel, NodeDeclarators declarators, NodeDeclarator declarator )
            : base( declarators, viewModel )
        {
            _declarator = declarator;

            // turn off node dragging and drawing connections
            _viewModel.IsEditMode = false;
        }

        #endregion C-tor

        #region IObjectManager implementation

        public void CreateObject( string className, Point position ) { }
        public void DeleteSelectedNodes() { }
        public void MoveNodes( IEnumerable<Tuple<double, double, string, NodeViewModel>> nodesData ) { }
        public void CreateConnection( ConnectorViewModel connectorDraggedOut, ConnectorViewModel connectorDraggedOver, ConnectionViewModel newConnection ) { }
        public void DeleteConnection( ConnectionViewModel connection ) { }
        public void DeleteConnections( IEnumerable<ConnectionViewModel> connection ) { }

        public async Task CreateDiagramAsync( string parentID )
        {
            await Task.Run( () =>
            {
                var nodeViewModels = new List<NodeViewModel>();
                if ( _declarator != null )
                {
                    // create node
                    var nodeViewModel = new DummyNodeViewModel( _declarators, _declarator );
                    nodeViewModel.InitFromNodeDeclarator( _declarator );
                    nodeViewModel.IsSelected = true;

                    nodeViewModels.Add( nodeViewModel );
                }

                // create connections
                var connectionViewModels = new List<ConnectionViewModel>();

                // create diagram
                _viewModel.CreateDiagram( nodeViewModels, connectionViewModels );
            } );
        }

        public void CreateConnectedObject( string className, Point position, ConnectionViewModel connection ) { }

        public bool ObjectHasOutputOfType( string nodeType, string outputType )
        {
            return false;
        }

        public void CreateDecoratorObject( string className, Point position, ConnectionViewModel connection ) { }
        public bool CanCopySelectedNodes()
        {
            return false;
        }

        public void CopySelectedNodes() { }
        public void CutSelectedNodes() { }

        public bool CanPasteNodes()
        {
            return false;
        }

        public void PasteNodes( Point position ) { }

        #endregion IObjectManager implementation
    }
}
